Merged
Conversation
Standardize binary data handling across the codebase by switching from Buffer to Uint8Array and adopting helper utilities from @btc-vision/bitcoin (toHex/fromHex/toBase64/fromBase64/equals/sha256). Update related types and function signatures (websocket payloads, merkle trees, block/transaction processing, API converters, broadcast/preimage routes, deployment encoder, etc.) and replace manual Buffer/from/toString conversions with the bitcoin helpers. Also bump several @btc-vision package versions in package.json. These changes improve consistency and interoperability of binary data handling and prepare the code for environments where Uint8Array is preferred.
Make defensive copies of Uint8Array data to prevent accidental mutation of shared buffers. Changes include slicing calldata in ContractEvaluator, returning copies of serialized input/output UTXOs in ContractEvaluation, copying various environment variable fields and originTweakedPublicKey in RustContract, and constructing revertData as a new Uint8Array. These are safety fixes to avoid side effects from consumers or native code modifying underlying buffers.
Replace .slice() calls with Uint8Array.from when creating/copying byte arrays across the VM/API/Rust boundary. This ensures true Uint8Array copies (avoiding shared ArrayBuffer/view issues) when parsing transactions, passing calldata, returning serialized UTXOs, and building Rust contract environment data. Updated files: BroadcastTransaction.ts, ContractEvaluator.ts, ContractEvaluation.ts, RustContract.ts.
Introduce an ESLint rule (eslint-rules/no-uint8array-tostring.ts) that warns against calling .toString() on Uint8Array/branded byte types (since it yields comma-separated decimals) and register it in eslint.config.js as opnet/no-uint8array-tostring (error). Update package.json to use a local @btc-vision/op-vm (file:../op-vm) and remove the opnet dependency. Adjust tests to use binary/Uint8Array representations and proper decoding: PluginBlockchainAPI tests now use Binary/Uint8Array for ids/hashes/inputs and expect hex strings, contract storage expects Uint8Array; PluginFilesystemAPI tests use TextDecoder.decode and Uint8Array for binary fixtures; PluginLoader test decodes parsed proto with TextDecoder. These changes prevent incorrect .toString() usage and align tests with byte/encoding handling.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Standardize binary data handling across the codebase by switching from Buffer to Uint8Array and adopting helper utilities from @btc-vision/bitcoin (toHex/fromHex/toBase64/fromBase64/equals/sha256). Update related types and function signatures (websocket payloads, merkle trees, block/transaction processing, API converters, broadcast/preimage routes, deployment encoder, etc.) and replace manual Buffer/from/toString conversions with the bitcoin helpers. Also bump several @btc-vision package versions in package.json. These changes improve consistency and interoperability of binary data handling and prepare the code for environments where Uint8Array is preferred.
Type of Change
Checklist
Build & Tests
npm installcompletes without errorsnpm run buildcompletes without errorsnpm testpasses all testsCode Quality
Documentation
Security
OPNet Node Specific
Testing
Consensus Impact
Related Issues
By submitting this PR, I confirm that my contribution is made under the terms of the project's license.